namespace AdminSG3L.Applicaticn.Commands;

/// <summary>
/// 统一API响应结果
/// </summary>
public class ApiResponse<T>
{
    /// <summary>
    /// 状态码（如200、400、500等）
    /// </summary>
    public int Code { get; set; }

    /// <summary>
    /// 响应消息
    /// </summary>
    public string Message { get; set; }

    /// <summary>
    /// 响应数据
    /// </summary>
    public T? Data { get; set; }

    /// <summary>
    /// 判断操作是否成功
    /// </summary>
    public bool IsSuccess => Code >= 200 && Code < 300;

    public ApiResponse(int code, string message, T? data = default)
    {
        Code = code;
        Message = message;
        Data = data;
    }

    /// <summary>
    /// 成功响应
    /// </summary>
    public static ApiResponse<T> Success(T? data, string message = "操作成功") => new ApiResponse<T>(200, message, data);
    /// <summary>
    /// 失败响应
    /// </summary>
    public static ApiResponse<T> Fail(string message, int code = 500) => new ApiResponse<T>(code, message, default);
} 
